from django.db import models


# Create your models here.
class Student(models.Model):
    SEX_CHOICES = (
        (0, '女'),
        (1, '男')
    )
    name = models.CharField(max_length=30, verbose_name='姓名')
    # null=True 字段值可以为空，blank=True 前端可以不传值
    age = models.IntegerField(verbose_name="年龄", null=True, blank=True)
    # choices添加数值的选项 在admin后台会变为下拉框
    sex = models.IntegerField(verbose_name='性别', null=True, blank=True, choices=SEX_CHOICES)
    creat_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
    is_delete = models.BooleanField(default=False, verbose_name="逻辑删除")
    classes = models.ForeignKey('Classes', on_delete=models.SET_NULL, null=True)

    def delete(self, using=None, keep_parents=False):
        # 重写删除的方法，把逻辑删除的值修改为True
        self.is_delete = True
        self.save()


class Classes(models.Model):
    name = models.CharField(max_length=30, verbose_name='班级名')
    slogan = models.TextField(null=True, blank=True, verbose_name="口号")
    creat_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
    is_delete = models.BooleanField(default=False, verbose_name="逻辑删除")
